Skip to content

Engine: Don't compile <% # comments %>#826

Merged
marcoroth merged 1 commit into
mainfrom
engine-strip-comments
Nov 9, 2025
Merged

Engine: Don't compile <% # comments %>#826
marcoroth merged 1 commit into
mainfrom
engine-strip-comments

Conversation

@marcoroth

@marcoroth marcoroth commented Nov 9, 2025

Copy link
Copy Markdown
Owner

Follow up to #825.

This pull request improves the engine by not compiling <% # coments %> comments as part of the template. Outputting # coments could lead to some cases, where the template could be compiled but couldn't be rendered, because it would comment out important pieces of the template.

<% if true %><% # comment %><%= "Hello World" %><% end %>

Before

exe/herb compile test.html.erb

__herb = ::Herb::Engine; _buf = ::String.new;
 if true; # comment
 _buf << __herb.h(("Hello World")); end; _buf << '
'.freeze;
_buf.to_s

After

exe/herb compile test.html.erb

__herb = ::Herb::Engine; _buf = ::String.new;
 if true; _buf << __herb.h(("Hello World")); end; _buf << '
'.freeze;
_buf.to_s

For reference

bin/erubi-compile test.html.erb

__erubi = ::Erubi; _buf = ::String.new; if true ; # comment ; _buf << __erubi.h(( "Hello World" )); end ; _buf << '
'.freeze;
_buf.to_s

bin/erubi-render test.html.erb

bin/erubi-render:117:in 'Kernel#eval': (eval at bin/erubi-render:117):2: syntax errors found (SyntaxError)
  1 | __erubi = ::Erubi; _buf = ::String.new; if true ; # comment ; _buf << __erubi.h(( "Hello World" )); end ; _buf << '
> 2 | '.freeze;
    | ^ unterminated string meets end of file
  3 | _buf.to_s
> 4 |
    | ^ expected an `end` to close the conditional clause

    | ^ unexpected end-of-input, assuming it is closing the parent top level context

        from bin/erubi-render:117:in 'ErubiRenderer#render_template'
        from bin/erubi-render:31:in 'ErubiRenderer#run'
        from bin/erubi-render:152:in '<main>'

exe/herb render test.html.erb

Hello World

@marcoroth marcoroth merged commit cb3c05e into main Nov 9, 2025
24 checks passed
@marcoroth marcoroth deleted the engine-strip-comments branch November 9, 2025 02:50
@marcoroth marcoroth changed the title Engine: Don't compile <% # coments %> Engine: Don't compile <% # comments %> Nov 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant